<% set_page_title(:project_all_issues, project_name: current_project.name) %>

<%= start_pending_app_tour_tag("issues/index") %>

<%= turbo_frame_tag 'new_issue_form', src: (params[:open_form] ? new_project_issue_path(current_project) : nil) do %>
<% end %>

<%= render partial: 'projects/navigation_header', locals: {
  project: current_project,
  header_width: true
} %>

<div class="px-8 grow w-header">
  <%= turbo_frame_tag 'issues', class: "tour--issues-list", autoscroll: true, 'autoblock-scroll': 'start', data: { turbo_action: "advance" } do %>

    <div class="card">
      <div class="card-body bg-base-100 border-base-300 rounded-box">
        <%= render partial: 'filter', locals: { q: @q } %>

        <div class="mb-2 flex justify-end gap-4 items-center flex-col lg:flex-row">
          <%= link_to new_project_issue_path(current_project),
              class: "btn btn-primary  tour--create-issue",
              data: { turbo_frame: 'new_issue_form' } do %>
              <%= icon_for(:add_entry) %>
              <%= "#{t('actions.create')} #{Issue.model_name.human.downcase}" %>
            <% end %>
        </div>

        <div class="overflow-x-auto">
          <% if @issues.empty? %>
            <p class="text-center text-base-content/80 text-lg font-semibold">
              <%= params[:q].present? ?
                  t("zero_records_for_this_search", resource_name: Issue.model_name.human) :
                  t("zero_records", resource_name: Issue.model_name.human)
              %>
            </p>
          <% else %>

            <table class="table table-header table-sm">
              <thead class="">
                <tr>
                  <th><%= sort_link(@q, :title, Issue.human_attribute_name(:title)) %></th>
                  <th><%= Issue.human_attribute_name(:labels) %></th>
                  <th><%= sort_link(@q, :groupings_title, Issue.human_attribute_name(:grouping)) %></th>
                  <th><%= sort_link(@q, :due_date, Issue.human_attribute_name(:due_date)) %></th>
                  <th class="text-center"></th>
                </tr>
              </thead>
              <tbody class="" id="all-issues-list">
                <% @issues.each do |issue| %>
                  <%= render partial: 'issue', locals: { issue: issue, project: current_project } %>
                <% end %>
              </tbody>
            </table>
            <%== pagy_summary(@pagy) %>
          <% end %>
        </div>
      </div>
    </div>
  <% end %>
</div>